package ${DAOImplPackage};

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import ${domainPackage}.${model.javaClass};
import com.cares.fw.database.dao.UpdateSQLParameter;
import ${DAOPackage}.${model.javaClass}DAO;
import com.cares.fw.database.dao.QueryDAO;
import com.cares.fw.database.dao.UpdateDAO;
<#if model.primaryImportClasses?exists>
<#list model.primaryImportClasses as p>
import ${p};
</#list>
</#if>

/**
 * This class was generated by SourceGenerator Tool.
 * This class corresponds to the database table ${model.tableName}.
 * 
 * @author SourceGenerator Tool.
 */
public class ${model.javaClass}DAOImpl implements ${model.javaClass}DAO {
	
	@Autowired
	QueryDAO queryDAO;
	
	@Autowired
	UpdateDAO updateDAO;	

	/**
	 * This method was generated by SourceGenerator Tool, do not modify.
	 * This method corresponds to the database table ${model.tableName}
	 */
	public List<${model.javaClass}> selectAllDatas() {
		return queryDAO.executeForObjectList("${model.tableName}.selectAllDatas", QueryDAO.EMPTY_PARAMS);
	}
	
	/**
	 * This method was generated by SourceGenerator Tool, do not modify.
	 * This method corresponds to the database table ${model.tableName}
	 */
	public ${model.javaClass} selectByPrimaryKey(${model.javaClass} obj) {
		return queryDAO.executeForObject("${model.tableName}.selectByPrimaryKey", obj, ${model.javaClass}.class);
	}
	
	/**
	 * This method was generated by SourceGenerator Tool, do not modify.
	 * This method corresponds to the database table ${model.tableName}
	 */
	public ${model.javaClass} selectByPrimaryKey(${model.primaryKeyArgs}) {
		${model.javaClass} obj = new ${model.javaClass}();
		<#if model.columnDefinitions.primaryKeyColumns?exists>
		<#list model.columnDefinitions.primaryKeyColumns as p>
		obj.${p.setterMothodName}(${p.javaProperty});
		</#list>
		</#if>
		
		return selectByPrimaryKey(obj);
	}
		
	/**
	 * This method was generated by SourceGenerator Tool, do not modify.
	 * This method corresponds to the database table ${model.tableName}
	 */	
	public int insert(${model.javaClass} obj) {
		return updateDAO.execute("${model.tableName}.insert", obj);
	}
	
	/**
	 * This method was generated by SourceGenerator Tool, do not modify.
	 * This method corresponds to the database table ${model.tableName}
	 */	
	public int updateByPrimaryKey(${model.javaClass} obj) {
		return updateDAO.execute("${model.tableName}.updateByPrimaryKey", obj);
	}
	
	/**
	 * This method was generated by SourceGenerator Tool, do not modify.
	 * This method corresponds to the database table ${model.tableName}
	 */	
	public int dynamicUpdateByPrimaryKey(${model.javaClass} obj, String[] updateColumns) {
		return updateDAO.execute("${model.tableName}.updateByPrimaryKeyWithLimit", 
				new UpdateSQLParameter(obj, updateColumns));
	}

	/**
	 * This method was generated by SourceGenerator Tool, do not modify.
	 * This method corresponds to the database table ${model.tableName}
	 */
	public int deleteByPrimaryKey(${model.javaClass} obj) {
		return updateDAO.execute("${model.tableName}.deleteByPrimaryKey", obj);
	}
	
	/**
	 * This method was generated by SourceGenerator Tool, do not modify.
	 * This method corresponds to the database table ${model.tableName}
	 */
	public int deleteByPrimaryKey(${model.primaryKeyArgs}) {
		${model.javaClass} obj = new ${model.javaClass}();
		<#if model.columnDefinitions.primaryKeyColumns?exists>
		<#list model.columnDefinitions.primaryKeyColumns as p>
		obj.${p.setterMothodName}(${p.javaProperty});
		</#list>
		</#if>
		
		return deleteByPrimaryKey(obj);	
	}
		
	/**
	 * This method was generated by SourceGenerator Tool, do not modify.
	 * This method corresponds to the database table ${model.tableName}
	 */
	public boolean isDuplicate(${model.javaClass} obj) {
		return (selectByPrimaryKey(obj) != null ? true : false);
	}
	
	/**
	 * This method was generated by SourceGenerator Tool, do not modify.
	 * This method corresponds to the database table ${model.tableName}
	 */
	public boolean isDuplicate(${model.primaryKeyArgs}) {
		${model.javaClass} obj = new ${model.javaClass}();
		<#if model.columnDefinitions.primaryKeyColumns?exists>
		<#list model.columnDefinitions.primaryKeyColumns as p>
		obj.${p.setterMothodName}(${p.javaProperty});
		</#list>
		</#if>
		
		return isDuplicate(obj);		
	}	
}
